﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSunny.Admin.Controls
{
    public partial class Vendor : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // Them du lieu vao cat 1
                DataTable dt = DAL.DCollector.DBCollector.Instance.StoredSelectTableWhereID("tbl_Category","Category_ID2", "0");
                ListItem lt = new ListItem("Chon danh muc", "-1");
                Cate1.Items.Add(lt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    lt = new ListItem(dt.Rows[i]["Category_Name"].ToString(), dt.Rows[i]["Category_ID1"].ToString());
                    Cate1.Items.Add(lt);
                }
                Cate1.SelectedIndex = 0;

            }
        }
        protected void Cate1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Chon danh muc cap 1 load danh muc cap 2
            

            int index = Cate1.SelectedIndex;
            if (index > 0)
            {
                int id = Convert.ToInt32(Cate1.SelectedValue);
                // Load du lieu
                DataTable dt = DAL.DCollector.DBCollector.Instance.StoredSelectTableWhereID("tbl_Vendor","Category_ID1", id.ToString());

                rpt_Vendor.DataSource = dt;
                rpt_Vendor.DataBind();

            }
        }

        protected void rpt_Vendor_ItemCommand1(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                // Xoa
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                DAL.DCollector.DBCollector.Instance.StoredDelete("tbl_Vendor", "Vendor_ID", id.ToString());
                Response.Redirect("/Admin/Index.aspx?panel=1&sub=2");
            }
        }
    }
}